import {
  Controller,
  Get,
  Req,
  HttpCode,
  Header,
  Redirect,
  Param,
  Body,
  Post,
} from '@nestjs/common';
import { Request } from 'express';
import { CatsService } from './cats.service';
import { Cat } from './interfaces/cat.interface';
import { CreateCatDto } from './dto/createa-cat.dto';
@Controller('cats')
export class CatsController {
  constructor(private catsService: CatsService) {}
  @Get()
  getAll(): string {
    return 'Here is all cats;';
  }

  @Get('/blue')
  @HttpCode(404)
  @Header('AAA', '1')
  //@Redirect('https://nestjs.com', 301)
  getBlue(@Req() request: Request): string {
    //console.log(request);
    return 'This action returns all cats,select is blue!';
  }

  @Get('/red')
  getRed(@Req() request: Request): string {
    //console.log(request);
    return 'This action returns all cats,select is red!';
  }

  @Get('a1a2**')
  getA(): string {
    return 'name start with a';
  }

  @Get('bbc/:id')
  getId(@Param('id') id: string): string {
    return id;
  }

  @Post('/create')
  async create(@Body() createCatDto: CreateCatDto) {
    console.log('🚀 ~ CatsController ~ create ~ createCatDto:', createCatDto);

    this.catsService.create(createCatDto);
    return { code: 200, message: 'success' };
  }

  @Get('/all')
  async findAll(): Promise<Cat[]> {
    return this.catsService.findAll();
  }
}
